// eslint-disable-next-line import/no-extraneous-dependencies
import { Request, Response } from 'express';

function fakeList(count: number) {
  const list = [
    {
      img: null,
      code: '101010',
      name: '胃康宁',
      desc: '24片/盒',
      otherName: 'ZZ-LFT-1:50',
      collected: true,
      number: 5,
      unit: '件',
      price: 14.5,
      saleUnit: '件',
    },
  ];
  for(let i = 0; i< count; i++) {
    list.push(list[0]);
  }

  return list;
}

function getFakeList(req: Request, res: Response) {
  const params = req.query as any;

  const count = (params.count) * 1 || 10;

  const result = fakeList(count);
  return res.json(result);
}

function getFakeCarts(req: Request, res: Response) {
  const params = req.query as any;

  const count = (params.count) * 1 || 10;

  const result = fakeCarts(count);
  return res.json(result);
}

function fakeCarts(count: number) {
  const cart = [
    {
      name: '胃康宁',
      code: '100100',
      price: 14.5,
      unit: '箱',
      volume: 50,
      volumeUnit: '盒',
      dosage: 'S4.7570 10mg',
      makerName: '上海XXX制药厂',
      number: 5.0,
      totalPrice: 72.5,
      saleUnit: '件',
      checked: false,
    },
  ];
  for(let i = 0; i< count; i++) {
    cart.push(cart[0]);
  }

  return cart;
}

export default {
  'GET  /_api/fake_list': getFakeList,
  'GET /_api/fake_cart': getFakeCarts,
};
